import { defineStore } from "pinia";
import axios from "axios";
export const useUsersStore = defineStore("shooing", {
  state() {
    return {
      addVisible: false,
      tableData: [],
      total: 0,
      pageSize: 3,
      currentPage: 1,
      serchcpunt: "",

      editVisible: false,
      godsId: 0,
      goodsForm1: {
        title: "",
        price: "",
      },
      imageUrl: "",
    };
  },
  actions: {
    //表格数据
    load() {
      axios
        .get("/goods", {
          params: {
            pageNumber: this.currentPage,
            pageSize: this.pageSize,
            search: this.serchcpunt,
          },
        })
        .then((res) => {
          //   console.log(res);
          this.tableData = res.data.list;
          this.currentPage = res.data.currentPage;
          this.total = res.data.totalCount;
        });
    },
    //用id查询的数据
    sjId() {
      axios
        .get("/goods/get", { params: { goodsId: this.godsId } })
        .then((res) => {
          //   console.log(res);
          this.goodsForm1.title = res.data.title;
          this.goodsForm1.price = res.data.price;
          this.imageUrl = import.meta.env.VITE_APP_URL + res.data.thumbnail;
        });
    },
  },
});
